﻿@using CodeCamp.Infrastructure.Extensions
@using CodeCamp.Models.Shared
@model CodeCamp.Models.Email.EmailPreviewViewModel

@{
    ViewBag.Title = "";
    if ((@Model != null) && (@Model.EventDisplayName != null))
    {
        ViewBag.Title = @Html.Encode(@Model.EventDisplayName + " | Email Preview");
    }
    else
    {
        ViewBag.Title = "Code Camp | Email Preview";
    }
}

@section headaddon {
<style>
    table
    {
        border-collapse: collapse;
        border: solid 1px;
        margin: 0;
    }
    th
    {
        padding: 4px;
    }
    td 
    {
        padding: 4px;
    }
</style>
}

<h2>Email Item Preview</h2>

@if (Model.EmailItem != null)
{
    using (Html.BeginForm()) {
    @Html.HiddenFor(model => model.EmailItemId)
    @Html.HiddenFor(model => model.ParentContext)
    <table>
        @if (Model.EmailItem.EmailCampaignId.HasValue)
        {
        <tr><th>Campaign:</th><td>@Model.EmailItem.EmailCampaign.Description.TruncateWithElipses(50)</td></tr>
        <tr><th>Campaign Status:</th><td>@Model.EmailItem.EmailCampaign.CampaignStatus.ToString()</td></tr>
        <tr><th>Recipient Type:</th><td>@Model.EmailItem.EmailCampaign.RecipientType.ToString()</td></tr>
        }
        <tr><th>Test Message:</th><td>@Model.EmailItem.TestMessage</td></tr>
        <tr><th>Status:</th><td>@Model.EmailItem.SendStatus.ToString()</td></tr>
        @if (Model.EmailItem.SentUTC.HasValue)
        {
        <tr><th>Sent (UTC):</th><td>@Model.EmailItem.SentUTC</td></tr>
        <tr><th>Sent By:</th><td>@Model.EmailItem.SentBy</td></tr>
        }
        <tr><th>Email View:</th><td>@Model.EmailItem.EmailView</td></tr>
        <tr><th>Reply To:</th><td>@Model.EmailItem.ReplyToAddress</td></tr>
        <tr><th>To:</th><td>@string.Format("{0} ({1})", string.Format("{0} {1}", Model.EmailItem.FirstName, Model.EmailItem.LastName).Trim(), Model.EmailItem.EmailTo)</td></tr>
        <tr><th>Subject:</th><td>@Model.EmailItem.SubjectToUse</td></tr>
        @if (Model.SendEnabled)
        {
        <tr>
            <td colspan="2" style="text-align:right;">
                    <input type="submit" value="Send" />
            </td>
        </tr>
        }
        @if (!string.IsNullOrWhiteSpace(Model.ParentContext))
        {
            <tr>
                <td colspan="2" style="text-align:right;">
    @{
        bool prevLink = false;
    switch (Model.ParentContext)
    {
        case "CampaignList":
            if (Model.EmailItem.EmailCampaignId.HasValue)
            {
                prevLink = true;
                @Html.ActionLink("Back to Campaign List", "EmailCampaignEmailList", new { eventName = Model.EventShortName, id = Model.EmailItem.EmailCampaignId.Value })
            }
            break;
        case "RecentEmails":
            prevLink = true;
                @Html.ActionLink("Back to Recent Emails List", "RecentEmails", new { eventName = Model.EventShortName })
            break;
    }
    if (Model.EnableEditLink)
    {
        if (prevLink) { <text> | </text> }
        @Html.ActionLink("Edit", "EmailItemEdit", new { eventName = Model.EventShortName, id = Model.EmailItemId })
    }
    <br />
    }
                </td>
            </tr>
        }
    </table>
    }
    if (!string.IsNullOrWhiteSpace(Model.EmailItem.EmailView))
    {
        <hr />
        var viewPath = string.Concat("~/Views/UserMailer/" + Model.EmailItem.EmailView, ".cshtml");
        @Html.Partial(viewPath, Model.EmailItem)
    }
    else
    {
        <h3>Email View not specified!</h3>
    }
}


@section sidebar {
    @if (User.IsInRole(CCRoles.RoleNames.BigCheeze))
    {
    <div id="eventTagsContainer" class="widget rounded-10">
    <ul>
        <li>@Html.ActionLink("Back to Email Home", "Index")</li>
        <li>@Html.ActionLink("Campaigns", "EmailCampaigns")</li>
        <li>@Html.ActionLink("Recent Emails", "RecentEmails")</li>
        <li>
            Email Tests:
            <ul>
                <li>@Html.ActionLink("Basic Test", "TestBasicMail")</li>
            </ul>
        </li>
    </ul>
    </div>
    }
}
